﻿using System;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace FscNET.Apm
{
    [StructLayout(LayoutKind.Sequential, Size = 1), DebuggerStepThrough]
    public struct EventApmFactory<TEventArgs>
    {
        public EventApmOperation<TEventArgs> PrepareOperation(AsyncCallback callback, object state)
        {
            return new EventApmOperation<TEventArgs>(callback, state);
        }

        public EventApmOperation<TEventArgs> PrepareOperation(AsyncCallback callback)
        {
            return new EventApmOperation<TEventArgs>(callback, null);
        }

        public TEventArgs EndInvoke(IAsyncResult result)
        {
            return ((AsyncResult<TEventArgs>)result).EndInvoke();
        }

        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return false;
            }
            return (obj.GetType() == GetType());
        }

        public static bool operator ==(EventApmFactory<TEventArgs> factory1, EventApmFactory<TEventArgs> factory2)
        {
            return factory1.Equals(factory2);
        }

        public static bool operator !=(EventApmFactory<TEventArgs> factory1, EventApmFactory<TEventArgs> factory2)
        {
            return !factory1.Equals(factory2);
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
    }


}
